<?php

namespace app\api\controller;

use app\BaseController;
use think\facade\Db; // 数据库的链接


class Notice extends BaseController
{
    public function getnotice()
    {
        $post = input();
        $page = @$post['page']? $post['page'] : 1;
        $limit = @$post['limit']? $post['limit'] : 10;
        $list = Db::name('notice')
        ->field("id,title,content,FROM_UNIXTIME(addto_time,'%Y-%m-%d %H:%i:%s') as addto_time")
        ->order('addto_time desc')
        ->paginate([
            'list_rows' => $limit,
            'page' => $page
        ])
        ->toArray();
        return json(['code' => 200,'data' => $list,'msg' => '获取成功']);
    }
    // 公告详情
    public function getnoticeinfo()
    {
        $post = input();
        $id = @$post['id'];
        $info = Db::name('notice')
            ->field("*,FROM_UNIXTIME(addto_time,'%Y-%m-%d %H:%i:%s') as addto_time")
            ->where('id',$id)
            ->find();
        return json(['code' => 200,'data' => $info,'msg' => '获取成功']);
    }
}